import {
    _get,
    _post
} from '../../../utils/request'
import util from '../../../utils/util'
const app = getApp()


Page({
    data: {
        edit_if: true,
        items: [],
        title: '',
        isshow_input: false,
        mb_name: ''
    },
    showPrompt() {
        this.setData({
            isshow_input: true
        })
    },
    showPrompt1() {
        this.setData({
            isshow_input: false
        })
    },
    bindKeyInput(e) {
        // console.log(e);
        this.setData({
            mb_name: e.detail.value
        })
    },
    //新增检测项
    async add() {
        let itemDto = {
            userId: app.userId,
            itemName: this.data.mb_name,
            vbizId: app.confirmId
        }
        await _post(`/item/editorItem`, itemDto).then(res => {
            console.log('编辑检测项成功');
        })
        this.getList()
        this.setData({
            // items: this.data.items.concat(params),
            isshow_input: false
        })
    },
    edit() {
        this.setData({
            edit_if: !this.data.edit_if
        })
    },
    delete(e) {
        console.log('del', e);
        let params = {
            sampleitemId: e.currentTarget.id,
            vbizId: app.confirmId
        }
        console.log('params', params);
        _get(`/item/deleteItem`, params).then(res => {
            dd.alert({
                    content: res.message
                })
                // console.log('删除成功', res);s
            this.getList()
        })

    },
    jump_equip() {
        dd.navigateTo({
            url: '/pages/equip/equip'
        })
    },
    jump_choosemb1(e) {
        app.ifTemplate = e.target.dataset.ifTemplate
        app.jcx_id = e.target.dataset.index
        console.log('检测项ID', app.jcx_id);
        dd.navigateTo({
            url: '/pages/choose_mb1/choose_mb1'
        })

    },
    jump_testing(e) {
        // console.log(e);
        app.testing_id = e.currentTarget.id
        dd.navigateTo({
            url: '/pages/mytest/testing/testing'
        })
    },
    getList() {
        let params = {
            userId: app.userId,
            workerId: app.test_id
        }
        _get(`/myTest/selectItemByUserIdAndWorkerId`, params).then(res => {
            console.log('检测项', res);
            this.setData({
                items: res.data.data,
                title: res.data.title
            })
        })
    },
    submitAll() {
        _post(`/myTest/allItem`, { vbizId: app.vbizId }).then(res => {
            console.log('是否跳转报告页', res);
            if (res.data == 0) {
                dd.alert({
                    content: '请完成所有检测后再填写报告'
                })
            } else if (res.data == null) {
                dd.alert({
                    content: '系统异常，请稍后重试'
                })
            } else if (res.data == 1) {
                dd.reLaunch({
                    url: '/pages/mytest/test_report/test_report'
                })
            } else if (res.data == 2) {
                dd.alert({
                    content: '请等待所有检测员完成检测'
                })
            }

        })

    },
    onLoad() {
        dd.setNavigationBar({
            title: '检测项列表',
            backgroundColor: '#142e4f',
            success() {},
            fail() {},
        });
        this.getList()
    },
});